﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**
*@file       posserversession.cs
*@brief      network session between game server and posserver
*
*@author     graywind
*@version    1.0.0.0
*@data       2012/01/04
*/

public class PosServerSession
{
    #region private variable
    //map to the session
    Dictionary<int, int> m_mapWorld = new Dictionary<int, int>();
    #endregion

    #region external call
    /// <summary>
    /// add a session
    /// </summary>
    /// <param name="world_id"></param>
    /// <param name="session_id"></param>
    /// <returns></returns>
    public bool Add(int world_id, int session_id)
    {
        lock (m_mapWorld)
        {
            if (!m_mapWorld.ContainsKey(world_id))
            {
                m_mapWorld.Add(world_id, session_id);
                return true;
            }
        }

        return false;
    }

    /// <summary>
    /// remove a session
    /// </summary>
    /// <param name="world_id"></param>
    public void Remove(int world_id)
    {
        lock (m_mapWorld)
        {
            if (m_mapWorld.ContainsKey(world_id))
                m_mapWorld.Remove(world_id);
        }
    }

    /// <summary>
    /// get the session
    /// </summary>
    /// <param name="world_id"></param>
    /// <returns></returns>
    public int GetSession(int world_id)
    {
        lock (m_mapWorld)
        {
            int session;
            if (m_mapWorld.TryGetValue(world_id, out session))
                return session;
        }

        return NetLib.INVALID_SESSION;
    }
    #endregion
}